Ext.define('AM.view.DeptFinaceView', {
		extend: 'Ext.grid.Panel',
		alias : 'widget.deptFinaceView',
		store : 'DeptFinaceStore',
		border:false,
		columnLines:true,
//		selModel : Ext.create('Ext.selection.CheckboxModel'), 
		selModel: {
	        injectCheckbox: 0,
	        mode: "SIMPLE"   //"SINGLE"/"SIMPLE"/"MULTI"
   		 },
   		selType: "checkboxmodel",
    	dockedItems: [{
        xtype: 'pagingtoolbar',
        dock: 'bottom',
        store : 'DeptFinaceStore',
        displayInfo: true
    }],
		columns: [	
			        {text: 'id', dataIndex: 'id',width:0,align:'center'},
			       // { text: '序号', width:50,align:'center',xtype: 'rownumberer'},
			        {text: '序号',  xtype: 'rownumberer',width:50,align:'center',tdCls:'background-color: #8EE5EE;'},
			        { text: '科室奖金',  dataIndex: 'deptFinace',  width:200,align:'center'},
			        { text: '科室',dataIndex: 'department', width:200,align:'center'},
			        { text: '日期',  dataIndex: 'date',  width:80,align:'center'}
			       
			     ],
			   tbar: [{
			   			 xtype : "numberfield",
						 fieldLabel: '奖金额',
						 labelWidth:50,
						 minValue:0,
						 name: 'reward',
						 id:'DeptdateReward'
			   		},{
					     xtype : "datefield",
						 fieldLabel: '查询日期',
						 labelWidth:60,
						 name: 'searchdate',
						 format:'Y-m',
						 id:'searchDeptdate',
						 listeners:{   
							select:function(field, value){
										 try{ 
										 var rewar;
										 Ext.Ajax.request({
												url : 'departmentFinaceAction_Empfinace',
											    async : false,
												success : function(response, options) {
													var re =Ext.JSON.decode(response.responseText);
													rewar=re.rewad;
												},
												failure : function() {
													Ext.MessageBox.alert("提示", "月无测算奖金！");
												},
												params : {
													searchdate:Ext.util.Format.date(this.value, 'Y-m')
												}
											});	
											 var parent=Ext.getCmp('DeptdateReward');
											 parent.reset();
											 parent.setValue(rewar);													 
										 }
										 catch(ex){
											 Ext.MessageBox.alert("错误","数据加载失败。");
										 }
									}
							}
					  },
					  { xtype: 'button', text: '查询',handler:saerchDeptFinace,icon : 'Ext/restful/images/find.png'
					  },
					  { xtype: 'button', text: '计算奖金',handler:countDeptFinaces,icon : 'Ext/restful/images/add.png'
					  },
					  { xtype: 'button',
			            text: '导出奖金',
			            icon : 'Ext/restful/images/down2.png',
			            margin: '0 0 0 15',
			            handler: function () {
			                 var searchdate = Ext.util.Format.date(Ext.getCmp('searchDeptdate').getValue(), 'Y-m');
			                 window.location.href ="exportExecleAction?searchdate="+searchdate+" ";
			       		 }
					  }
					]
})
function countDeptFinaces() {
	     var grid=this.ownerCt.ownerCt;
	     var fiance= Ext.getCmp('DeptdateReward').getValue();
	     var date= Ext.getCmp('searchDeptdate').getValue();
	     var searchdate= Ext.util.Format.date(date, 'Y-m');
   		 Ext.Ajax.request({
					url : 'departmentFinaceAction_CountDepartmentFinace',
					success : function() {
						grid.getStore().on('beforeload', function (store, options) {
				          var new_params = {searchdate:searchdate}
				                Ext.apply(store.proxy.extraParams, new_params);
				       });//此处为加载条件
						  grid.getStore().reload();
								},
					failure : function() {
						Ext.MessageBox.alert("提示", "计算奖金失败！");
					},
					params : {
							reward:fiance,
							searchdate:searchdate
					}
		});	
		
}
function saerchDeptFinace() {
   		 var grid=this.ownerCt.ownerCt;
   		 var date= Ext.getCmp('searchDeptdate').getValue();
	     var searchdate= Ext.util.Format.date(date, 'Y-m');
		 grid.getStore().on('beforeload', function (store, options) {
	          var new_params = {searchdate:searchdate}
	                Ext.apply(store.proxy.extraParams, new_params);
	       });//此处为加载条件
			  grid.getStore().reload();				
}